package src.leetcode.hot.mid_0452;

import java.util.Arrays;
import java.util.Comparator;

public class findMinArrowShots {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] points = {{1,2}, {3,4}, {5, 6}, {7, 8}};
        System.out.println(solution.findMinArrowShots(points));
    }
}

class Solution {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparing(o -> o[0]));

        int right = points[0][1];
        int count = 1;
        for (int[] point : points) {
            if (point[0] <= right) {
                right = Math.min(right, point[1]);
            } else {
                count++;
                right = point[1];
            }
        }
        return count;
    }
}